package com.woniu.user.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.woniu.user.domain.Doctor;
import com.woniu.user.vo.DeptVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.woniu.user.domain.Dept;
import com.woniu.user.service.IDeptService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 部门表Controller
 *
 * @author wolf-six
 * @date 2023-02-15
 */
@RestController
@RequestMapping("/dept")
public class DeptController extends BaseController
{
    @Autowired
    private IDeptService deptService;


    /**
     * 查询部门医师对应列表
     */
    @RequiresPermissions("user:dept:list")
    @GetMapping("/getdeptList")
    public AjaxResult getdeptList()
    {

        return success(deptService.getdeptList());
    }

    /**
     * 查询部门表列表
     */
    @RequiresPermissions("user:dept:list")
    @GetMapping("/list")
    public TableDataInfo list(Dept dept)
    {
        startPage();
        List<Dept> list = deptService.selectDeptList(dept);
        return getDataTable(list);
    }

    /**
     * 导出部门表列表
     */
    @RequiresPermissions("user:dept:export")
    @Log(title = "部门表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Dept dept)
    {
        List<Dept> list = deptService.selectDeptList(dept);
        ExcelUtil<Dept> util = new ExcelUtil<Dept>(Dept.class);
        util.exportExcel(response, list, "部门表数据");
    }

    /**
     * 获取部门表详细信息
     */
    @RequiresPermissions("user:dept:query")
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId)
    {
        return success(deptService.selectDeptByDeptId(deptId));
    }

    /**
     * 新增部门表
     */
    @RequiresPermissions("user:dept:add")
    @Log(title = "部门表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Dept dept)
    {
        return toAjax(deptService.insertDept(dept));
    }

    /**
     * 修改部门表
     */
    @RequiresPermissions("user:dept:edit")
    @Log(title = "部门表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Dept dept)
    {
        return toAjax(deptService.updateDept(dept));
    }

    /**
     * 删除部门表
     */
    @RequiresPermissions("user:dept:remove")
    @Log(title = "部门表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deptIds}")
    public AjaxResult remove(@PathVariable Long[] deptIds)
    {
        return toAjax(deptService.deleteDeptByDeptIds(deptIds));
    }

    @GetMapping("/de/{id}")
    public Dept selectById(@PathVariable("id") long id){
        return deptService.selectById(id);
    }
    /**
     * 查询所有的科室
     */
    @GetMapping("/selAllDept")
    public List<DeptVo> selAllDept(){
        return deptService.selAllDept();
    }
}
